﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonGenerator
{
    class Map
    {
        public static List<Room> tempRoom = new List<Room>();
        public static List<MapTile> map = new List<MapTile>();
        public static Random rand = new Random((Int32)System.DateTime.Now.Ticks);


        public static void generateMap(int rooms)
        {
            map.Clear();
            tempRoom.Clear();

            for (int i = 0; i < rooms; i++)
            {
                generateRoom(rand.Next(9,20));
            }
        }

        public static void generateRoom(int size)
        {
            tempRoom.Clear();

            int tempX, tempY;
            tempX = rand.Next(Program.SCREENMIN, Program.SCREENX);
            tempY = rand.Next(Program.SCREENMIN, Program.SCREENY);

            for (int i = 0; i < size+1; i++)
            {
                tempRoom.Add(new Room(tempX+i,tempY, '#'));
                tempRoom.Add(new Room(tempX, tempY + i, '#'));
                tempRoom.Add(new Room(tempX+size, tempY + i, '#'));
                tempRoom.Add(new Room(tempX+i, tempY+size, '#'));
            }

            foreach (Room room in tempRoom)
            {
                map.Add(new MapTile(room.x, room.y, room.tile));
            }
        }

        public static void drawMap()
        {
            foreach (MapTile tile in map)
            {
                if (tile.x > Program.SCREENX) { }
                else if (tile.y > Program.SCREENY) { }
                else
                {
                    Console.SetCursorPosition(tile.x, tile.y);
                    Console.Write(tile.tile);
                }
            }
        }
    }

    public class Tile
    {
        public int x, y;
        public char tile;
    }

    public class MapTile:Tile
    {
        public MapTile(int tempX, int tempY, char tempTile)
        {
            x = tempX;
            y = tempY;
            tile = tempTile;
        }
    }

    public class Room:Tile
    {
        public Room(int tempX, int tempY, char tempTile)
        {
            x = tempX;
            y = tempY;
            tile = tempTile;
        }
    }
}
